﻿Imports System.Xml.Linq
Imports System.Globalization
Imports System.Text

Public NotInheritable Class ExceptionFactory
    Private Sub New()

    End Sub

    Private Shared _localizedResources As New AppResources()

    Public Shared Function CreateException(ex As Exception) As Exception
        If ex Is Nothing Then Throw New ArgumentNullException()
        Dim exceptionCode = SpeechHResults.GetCodeByHResult(ex.HResult)
        If Not String.IsNullOrWhiteSpace(exceptionCode) Then
            Dim resKey = String.Format("HR_{0:X}", ex.HResult)
            Dim description = _localizedResources.ResourceManager.GetString(resKey)
            Return New SpeechException(description, ex) With {.ErrorCode = exceptionCode}
        End If
        Return ex
    End Function

End Class
